<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    [#include "/includes/header.html" /]
    <style type="text/css">
        .dd {
            float: left;
            width: 20%;
        }

        .dd-handle-bk-color {
            background: #d4d4d4;
        }
    </style>
    <script type="text/javascript">
        var qname = "";
        $(document).ready(function () {

            //批量删除
            $("#mypromotionDelBtn").click(function () {
                var count = TBatch.getCheckedCount();
                if (count == 0) {
                    obz.showMessage("请选择一个活动");
                } else {
                    obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function () {
                        var ids = TBatch.getChecked();
                        obz.ajaxJson(obz.ctx + "/cashback/del", {ids: ids}, function (resp) {
                            if (resp.code == 200) {
                                searchpromotions();
                            }
                        });
                    });
                }
            });

            searchpromotions();
        });

        var pageClick = function (pageNo) {
            searchpromotions(pageNo);
        }

        var searchpromotions = function (currPage) {
            var params = {};
            //其他查询条件
            if (currPage) {
                params.page = currPage;
            }
            params.qname = qname;
            params.type = $("#a_type_sel").val();
            params.status = $("#a_status_sel").val();

            $("#mainTable").mask("加载中...");
            var url = obz.ctx + "/reward/list";
            obz.ajaxJson(url, params, function (resp) {
                $("#mainTable").unmask();
                var result = resp.data;
                $(".promotionLotGrid").empty();
                if (currPage) {
                    $("#pager").pager({
                        pagenumber: currPage,
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                } else {
                    $("#pager").pager({
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                }
                var dataList = result.list;
                if (dataList.length > 0) {
                    for (var i = 0; i < dataList.length; i++) {
                        var _row = dataList[i];
                        var trHtml = obz.dataTemplate4obj($("#cashback_table_tr_tpl").html(), _row);
                        $(".cashbackLotGrid").append(trHtml);
                    }
                    TBatch.checkCheckbox();
                    TBatch.initCheckboxClick();
                    TBatch.initOptEvent(ActivityTableOpt.init());
                } else {
                    $(".cashbackLotGrid").append($("#table_noresult_tr_tpl").html());
                }
            });
        }

        //=============================表格操作事件开始=============================================
        var ActivityTableOpt = {
            edit: function (param) {
                var id = param[1];
                location.href = obz.ctx + "/reward/set/?pid=" + id;
            },
            del: function (param) {
                obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/cashback/del", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            searchpromotions();
                        }
                    });
                });
                return false;
            },
            init: function () {
                var optArray = new Array();
                optArray.push(this.edit);
                optArray.push(this.del);
                return optArray;
            }
        }
        //=============================表格操作事件结束=============================================
    </script>
</head>

<body class="fixed-sidebar full-height-layout gray-bg">
[#include "/includes/menus.html" /]
<div class="wrapper wrapper-content">
    <div class="row content-tabs">
        <nav class="page-tabs J_menuTabs">
            <div class="page-tabs-content" style="margin-left: 0px;">
                <a href="${webctx}/promotion" class="J_menuTab">限时打折</a>
                <!-- <a href="${webctx}/cashback" class="J_menuTab">订单返现</a> -->
                <a href="${webctx}/reward" class="J_menuTab active">满减送</a>
            </div>
        </nav>
    </div>
    <div id="tableList" class="content row ibox-content">
        <div class="panel-body">
            <a href="${webctx}/reward/set" class="btn btn-success">新建满减送</a>
        </div>
        <div>更多营销活动，请升级到企业版</div>
    </div>
</div>
[#include "/includes/footer.html" /]
<script>
    Template.init("#menu-discount");
</script>
</body>
</html>